package special;

import node.ListNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Solution1 {
    List<Integer> list = new ArrayList<>();
    Random r = new Random();
    public Solution1(ListNode head) {
        while (head != null){
            list.add(head.val);
            head = head.next;
        }
    }
    
    public int getRandom() {
        return list.get(r.nextInt(list.size()));
    }
}